import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:travel/components/follow/index.dart';
import 'package:travel/utils/colors.dart';
import 'package:travel/utils/styles.dart';
import 'package:travel/utils/tools.dart';
import 'package:travel/screen/flutter_screenutil.dart';

class FollowFansController extends GetxController with GetTickerProviderStateMixin {
  late TabController tabController;

  RxInt index = 0.obs;

  RxList<String> tabs = RxList(['关注 23', '粉丝 1.2万']);

  @override
  void onInit() {
    if (Get.arguments != null) {
      index.value = Get.arguments['index'];
    }
    tabController = TabController(length: tabs.length, vsync: this, initialIndex: index.value);
    super.onInit();
  }

  @override
  void onClose() {
    tabController.dispose();
    super.onClose();
  }
}

class FollowFansView extends GetView<FollowFansController> {
  const FollowFansView({super.key});

  @override
  Widget build(BuildContext context) {
    return Obx(() => Scaffold(
          backgroundColor: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF7f7),
          appBar: AppBar(
            automaticallyImplyLeading: true,
            backgroundColor: Colors.white,
            leading: InkWell(
              onTap: () {
                Get.back();
              },
              child: Icon(
                Icons.arrow_back_ios,
                color: ColorsUtils.parseColorFromHexString(ColorsUtils.color3333),
                size: 20.w,
              ),
            ),
            leadingWidth: 40.w,
            title: Text(
              '关注与粉丝',
              style: StylesUtils.customTextStyle(fontSize: 18.sp, color: ColorsUtils.color0000),
            ),
            elevation: 0,
            bottom: bottom,
          ),
          body: TabBarView(
            controller: controller.tabController,
            children: const [FollowPage(), FansPage()],
          ),
        ));
  }

  PreferredSize get bottom {
    return PreferredSize(
      preferredSize: Size.fromHeight(40.h),
      child: Container(
        height: 40.h,
        decoration: BoxDecoration(
            border: Border(
                bottom:
                    BorderSide(color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF5f5)))),
        padding: EdgeInsets.only(left: 15.w),
        alignment: Alignment.centerLeft,
        child: ToolsUtils.getClientTabBar(controller.tabs, controller.tabController,
            isScrollable: false, indicatorSize: TabBarIndicatorSize.tab, onTap: (int index) {
          controller.index.value = index;
        }),
      ),
    );
  }
}
